<template>
	<view class="add">
		<!-- 主要信息 -->
		<add-list :addressObject="addressObject"></add-list>
		<!-- 底部按钮 -->
		<view class="bottom">
			<view class="btn" @click="gotoAddAddress">
				<text>保存地址</text>
			</view>
		</view>

	</view>
</template>

<script>
	import addList from './add-child/add-list.vue'

	import {
		addShopAddress
	} from '@/api/http/main/market/address.js'

	export default {
		components: {
			addList
		},
		data() {
			return {
				addressObject: {
					//地址
					address: '',
					//纬度
					latitude: '',
					//精度
					latitude: '',
					accuracy: '',
					detailAddress: '',
					name: '',
					phone: '',
					//是否为默认地址
					isDefault: '0'
				}
			}
		},
		methods: {
			gotoAddAddress() {
				if (this.addressObject.address == '' || this.addressObject.address == null ||
					this.addressObject.detailAddress == '' || this.addressObject.detailAddress == null ||
					this.addressObject.name == '' || this.addressObject.name == null ||
					this.addressObject.phone == '' || this.addressObject.phone == null
				) {
					return uni.$showMsg('请填写完整地址信息！');
				}

				addShopAddress(this.addressObject).then(res => {
					if (res.data.pubInfo.code !== 0) {
						return uni.$showMsg(res.data.pubInfo.message);
					}
					uni.$showMsg('添加成功！');
					this.goBack()
				})
			},
			goBack() {
				var pages = getCurrentPages(); //当前页面栈  
				let beforePage = pages[pages.length - 2]; //获取上一个页面实例对象  
				beforePage.$vm.getAddress(); //触发上一个页面中的getUserInfo方法
				//uni.navigateBack();

				uni.navigateBack({
					delta: 1, //返回层数，2则上上页
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.add {
		width: 100%;
		height: 100vh;
		background: rgba(240, 245, 242, 1);
	}

	.bottom {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 130rpx;
		background: #fff;

		.btn {
			margin-top: 10rpx;
			width: 90%;
			margin-left: 5%;
			height: 80rpx;
			background: rgba(10, 163, 71, 1);
			text-align: center;
			line-height: 80rpx;
			border-radius: 40rpx;

			text {
				font-size: 30rpx;
				font-weight: 400;
				color: rgba(255, 255, 255, 1);
			}

		}
	}
</style>
